package com.meixun.xuanke.course.util;

import java.util.Calendar;
import java.util.HashMap;

public class StuUtil {
	
	public static String getGradeName(Integer classTypeId,Integer grade,String schoolClassName) {
	
	  Integer gradeName = 0;
		
	  if (classTypeId == 1) {
		  gradeName = 0;
	  } if (classTypeId == 2) {
		  gradeName = 0;
	  }else if (classTypeId == 3) {
		  gradeName =6;
	  }else if (classTypeId == 4) {
		  gradeName = 9;
	  }

      Calendar cal2 = Calendar.getInstance();
      int year = cal2.get(1);
      int mouth = cal2.get(2) + 1;

      if(grade>0){
		  if (mouth >= 8)
	      	grade = Integer.valueOf(year - grade + 1);
	      else {
	      	grade = Integer.valueOf(year - grade);
	      }
      }
      
      String last="";
      if((classTypeId == 1&&grade>1) ||(classTypeId == 2&&grade>6) || ((classTypeId ==3|| classTypeId == 4)&&grade>3)){
		  if(classTypeId == 2 && grade>6){
			  grade=6;
		  }
		  if((classTypeId == 3|| classTypeId == 4)&&grade>3){
			  grade=3;
		  }
    	  last="(已毕业)";
	  }

      return getGrade(gradeName+grade)+"年级"+schoolClassName+last;
	}
  public static String getGradeName(Integer classTypeId,Integer grade) {
		
	  Integer gradeName = 0;
		
	  if (classTypeId == 1) {
		  gradeName = 0;
	  } if (classTypeId == 2) {
		  gradeName = 0;
	  }else if (classTypeId == 3) {
		  gradeName =6;
	  }else if (classTypeId == 4) {
		  gradeName = 9;
	  }

      Calendar cal2 = Calendar.getInstance();
      int year = cal2.get(1);
      int mouth = cal2.get(2) + 1;

      if(grade>0){
		  if (mouth >= 8)
	      	grade = Integer.valueOf(year - grade + 1);
	      else {
	      	grade = Integer.valueOf(year - grade);
	      }
      }
      String last="";
      if((classTypeId == 1&&grade>1) ||(classTypeId == 2&&grade>6) || ((classTypeId == 3|| classTypeId == 4)&&grade>3)){
      	  if(classTypeId == 2 && grade>6){
			  grade=6;
		  }
		  if((classTypeId == 3|| classTypeId == 4)&&grade>3){
			  grade=3;
		  }
    	  last="(已毕业)";
	  }
      
      return getGrade(gradeName+grade)+"年级"+last;
    }
	  public static String getGradeName2(Integer period,Integer grade) {
		  Integer gradeName = 0;
		  
		  Calendar cal2 = Calendar.getInstance();
		  int year = cal2.get(1);
		  int mouth = cal2.get(2) + 1;
		  
		  if(grade>0){
			  if (mouth >= 8) {
				  grade = Integer.valueOf(year - grade + 1);
			  }else {
				  grade = Integer.valueOf(year - grade);
			  }
		  }
		  
		  if((period == 1&&grade>1) && (period == 2&&grade>6) || ((period == 3|| period == 4)&&grade>3)){
			  return "";
		  }
		  
		  if (period == 1) {
			  gradeName = 0;
		  } if (period == 2) {
			  gradeName = 0;
		  }else if (period == 3) {
			  gradeName =6;
		  }else if (period == 4) {
			  gradeName = 9;
		  }
          String last="";
          if((period == 1&&grade>1) ||(period == 2&&grade>6) || ((period == 3|| period == 4)&&grade>3)){
              if(period == 2 && grade>6){
                  grade=6;
              }
              if((period == 3|| period == 4)&&grade>3){
                  grade=3;
              }
              last="(已毕业)";
          }
		  return getGrade(gradeName+grade)+"年级"+last;
	  }
  
  
  
    public static String getGrade(Integer grade){
    	String result="";
    	switch (grade) {
    	case 0:
    		result="学前";
    		break;
		case 1:
			result="一";
			break;
		case 2:
			result="二";
			break;
		case 3:
			result="三";
			break;
		case 4:
			result="四";
			break;
		case 5:
			result="五";
			break;
		case 6:
			result="六";
			break;
		case 7:
			result="七";
			break;
		case 8:
			result="八";
			break;
		case 9:
			result="九";
			break;
		case 10:
			result="十";
			break;
		case 11:
			result="十一";
			break;
		case 12:
			result="十二";
			break;
		case 13:
			result="十三";
			break;
		default:
			break;
		}
    	return result;
    }
    
    public static Integer getGradeNum(String grade){
    	Integer result=null;
    	if(grade.indexOf("(已毕业)")>-1){
    		grade=grade.replace("(已毕业)","");
		}
    	if(grade.equals("学前年级")){
    		result=0;
    	}else if(grade.equals("一年级")){
    		result=1;
    	}else if(grade.equals("二年级")){
    		result=2;
    	}else if(grade.equals("三年级")){
    		result=3;
    	}else if(grade.equals("四年级")){
    		result=4;
    	}else if(grade.equals("五年级")){
    		result=5;
    	}else if(grade.equals("六年级")){
    		result=6;
    	}else if(grade.equals("七年级")){
    		result=7;
    	}else if(grade.equals("八年级")){
    		result=8;
    	}else if(grade.equals("九年级")){
    		result=9;
    	}else if(grade.equals("十年级")){
    		result=10;
    	}else if(grade.equals("十一年级")){
    		result=11;
    	}else if(grade.equals("十二年级")){
    		result=12;
    	}
    	return result;
    }
    
    public static Integer getGrade(String grade){
    	Integer result=null;
    	if(grade.equals("学前年级")){
    		result=0;
    	}else if(grade.equals("一年级")){
    		result=1;
    	}else if(grade.equals("二年级")){
    		result=2;
    	}else if(grade.equals("三年级")){
    		result=3;
    	}else if(grade.equals("四年级")){
    		result=4;
    	}else if(grade.equals("五年级")){
    		result=5;
    	}else if(grade.equals("六年级")){
    		result=6;
    	}else if(grade.equals("七年级")){
    		result=1;
    	}else if(grade.equals("八年级")){
    		result=2;
    	}else if(grade.equals("九年级")){
    		result=3;
    	}else if(grade.equals("十年级")){
    		result=1;
    	}else if(grade.equals("十一年级")){
    		result=2;
    	}else if(grade.equals("十二年级")){
    		result=3;
    	}
    	return result;
    }
    
    public static String getGradeName(HashMap<String, Object> hashMap){
    	Integer ClassTypeID = (Integer) hashMap.get("period");
		Integer grade = Integer.valueOf(hashMap.get("grade")+"");
		String className = (String) hashMap.get("className");
		return StuUtil.getGradeName(ClassTypeID, grade, className);
    }
    public static int getGrade(int grade,int ClassTypeID){
		int Gradeid=0;
		Calendar cal2 = Calendar.getInstance();
		int year = cal2.get(1);
		int mouth = cal2.get(2) + 1;

		if(grade>0){
			if (mouth >= 8) {
				grade = Integer.valueOf(year - grade + 1);
			}else {
				grade = Integer.valueOf(year - grade);
			}
		}

		if(ClassTypeID==1){
			Gradeid= grade;
		}else if (ClassTypeID==2){
			Gradeid= grade+6;
		}else if (ClassTypeID==3){
			Gradeid= grade+9;
		}
		return Gradeid;
    }
}
